package com.hhh.petadopt.serviceImpl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.hhh.petadopt.mapper.AdoptMapper;
import com.hhh.petadopt.pojo.Adopt;
import com.hhh.petadopt.pojo.Pet;
import com.hhh.petadopt.service.AdoptService;
/**
 * 收养列表
 * @author 杜镇声声
 *
 */
@Controller
public class AdoptServiceImpl implements AdoptService {
	@Autowired
	private AdoptMapper adoptMapper;

	//动物列表展示
	@Override
	public List<Pet> selectPetLimit() {
		List<Pet> petList = adoptMapper.selectPetList();
		return petList;
	}

	//根据id查询动物信息
	@Override
	public Pet selectPetById(Long id) {
		//根据id查询动物描述
		String pdesc = adoptMapper.selectDescById(id);
		//查询动物信息
		Pet petInfo = adoptMapper.selectPetById(id);
		//将动物描述封装返回
		petInfo.setPdesc(pdesc);
		return petInfo;
	}

	//收养信息入库
	@Override
	public void saveAdoptPet(Adopt ap) {
		//补全信息
		ap.setAdoptgrant("2");
		ap.setCreated(new Date());
		ap.setUpdated(new Date());
		//1.信息入库
		adoptMapper.saveAdoptPet(ap);
		//根据id删除pet表中的动物信息
		adoptMapper.delPetById(ap.getAdoptnum());
		//根据id删除描述
		adoptMapper.delDescById(ap.getAdoptnum());
		
	}

}
